package com.passion.exception;

import com.passion.common.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * @program offline-e-commerce-data-warehouse
 * @Description
 * @Author limeihua
 * @Date 2024/09/28 19:18
 * @Version 1.0
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 计算异常处理
     *
     * @param arithmeticException
     * @return
     */
    @ExceptionHandler(ArithmeticException.class)
    public R error(ArithmeticException arithmeticException) {
        return R.error(500, arithmeticException.getMessage());
    }


    /**
     * 未知异常处理
     * @param e
     * @return
     */
//    @ExceptionHandler(Throwable.class)
//    public R error(Throwable e) {
//        return R.error(500, e.getMessage());
//    }

    /**
     * 任务类型异常处理
     *
     * @param exception
     * @return
     */
    @ExceptionHandler(TaskTypeDataException.class)
    public R error(TaskTypeDataException exception) {
        return R.error(exception.getCode(), exception.getExceptionMessage());
    }
}
